# _*_conding:utf-8_*_
# 作者: atao
# 创建时间: 2022年2月24日12点32分
# 文件: redishelper
import requests
from application import settings

'''
    根据接口服务提供接口，对redis服务进行访问

'''


class RedisHelper():
    _url = settings.REDIS_API_HOST
    _headers = {'content-type': "application/json"}

    @classmethod
    def set(cls, key, value):
        resp = requests.post(cls._url, json={"key": key, "value": value}, headers=cls._headers).json()
        if not resp['code'] == 5:
            raise Exception('数据写入失败，请检查!')
        return resp

    @classmethod
    def get(cls, key):
        resp = requests.get('/'.join((cls._url, key)), headers=cls._headers).json()
        if not resp['code'] == 5:
            raise Exception('数据读取失败，请检查!')
        return resp

    @classmethod
    def delete(cls, key):
        resp = requests.delete('/'.join((cls._url, key)), headers=cls._headers).json()
        if not resp['code'] == 5:
            raise Exception('数据读取失败，请检查!')
        return resp


if __name__ == '__main__':
    key = 'setting:sysdic:48'
    value = '333'
    # RedisHelper.set(key, value)
    # RedisHelper.get(key)
    # RedisHelper.delete(key)
    # RedisHelper.get(key)
    # resp = requests.get(url='http://10.192.19.33:8085/InfoController/road/3/', data=[]).json()
    # print(resp)
